var app = angular.module('MainControllers', []);

var params = {
    orgin: 'stream',
    CommandName: "GET_FAV_ITEM_ROLE",
    PrincipalId: "undefined",
    Params: null
};

app.controller('MainController', ['$scope', '$http', 'commonConfig',
    function ($scope, $http, commonConfig) {
        $http({
            method: 'POST',
            url: commonConfig.DbAddress,
            data: angular.toJson(params),
            headers: {
                'Content-Type': 'application/json; charset=UTF-8'
            },
            transformResponse: function (data) {
                return data;
            }
        }).success(function (data, status, headers, config) {
            if (status === 200) {
                if (typeof(data) === "string") {
                    data = eval("(" + data + ")");
                }
                var dsRsp = new DataServiceResponse(data.affectedRows, data.columnNames, data.resultCode, data.resultDesc, data.rows);
                $scope.users = dsRsp.Rows;
            }
        }).error(function (data, status, headers, config) {
            console.log('error');
        });

        function DataServiceResponse(affectedRows, columnNames, resultCode, resultDesc, rows) {
            this.AffectedRows = affectedRows; //int
            this.ColumnNames = columnNames; //string[]
            this.ResultCode = resultCode; //string
            this.ResultDesc = resultDesc; //string
            this.Rows = rows; //object[][]
        }
    }
]);